package com.example.demo;

import java.util.concurrent.CountDownLatch;

/**
 * @program: springboot_course
 * @description:
 * @author: ChenZhiXiang
 * @create: 2019-08-20 19:34
 **/
public class ThreadTest {

    /**初始化CountDownLatch，值为线程数量*/
    private static final CountDownLatch c = new CountDownLatch(10);

    public static void test(){
        for (int i =0; i < 10;i++){
            try {
                new Thread(() -> {
                    System.out.println("子线程执行"+Thread.currentThread().getName());
                }).start();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                c.countDown();
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        System.out.println("主线程开始");
        test();
        c.await();
        System.out.println("主线程结束");
    }
}
